package zhaolongli_Boundary;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;


import zhaolongli_Controller.ChoiceController;
import zhaolongli_Entity.Model;

/** the main window of the application*/

public class Application extends JFrame {

	Model m;
	private MyPanel contentPane = null;
	private JPanel choicePanel;
	
	MyTextField[] choices;
	

	/**
	 * Create the frame.
	 */
	public Application(Model m) {
		setResizable(false);
		this.m = m;
		setTitle("Decision Line A1 Version");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);

		
		//initialized myPanel
		contentPane = getMyPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);

		
		choicePanel = new JPanel();
		choicePanel.setBounds(20, 100, 650, 45);
		getContentPane().add(choicePanel);
		
		// add the textField into Panel		
		choices = new MyTextField[m.getN()];
		for (int i = 0; i < m.getN(); i++) {
			choices[i] = new MyTextField (i);
			choices[i].setColumns(50/m.getN());
			choices[i].setEditable(true);
			choices[i].setFont(new Font ("Tahoma", Font.PLAIN, 11));
			choices[i].addActionListener(new ChoiceController (m, choices[i]));
			choicePanel.add(choices[i]);
			
		}	
		
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(25)
					.addComponent(choicePanel, GroupLayout.PREFERRED_SIZE, 635, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(240, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(106)
					.addComponent(choicePanel, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(428, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);
		
		
	}

	/**
	 * get the content Panel if it exist, otherwise create one.
	 * @return
	 */
	public MyPanel getMyPanel(){
		if(this.contentPane == null){
			this.contentPane = new MyPanel(m);
			return this.contentPane;
		}
		return contentPane;
	}
	
	

}
